function getAddressById(addressId, callback) {
    $.ajax({
        type: 'post',
        url: '/userAddress/getAddressById',
        data: {
            addressId: addressId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                callback(result.data);
            } else {
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}
function getNoDefaultAddress(userId, callback) {
    $.ajax({
        type: 'post',
        url: '/userAddress/getNoDefaultAddress',
        data: {
            userId: userId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                callback(result.data);
            } else {
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}

function getDefaultAddress(userId, callback) {
    $.ajax({
        type: 'post',
        url: '/userAddress/getDefaultAddress',
        data: {
            userId: userId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                callback(result.data);
            } else {
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}

function setDefaultAddress(userId, addressId) {
    $.ajax({
        type: 'post',
        url: '/userAddress/setDefaultAddress',
        data: {
            userId: userId,
            addressId: addressId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                location.reload();
            } else {
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}

function deleteAddress(addressId) {
    $.ajax({
        type: 'post',
        url: '/userAddress/deleteById',
        data: {
            addressId: addressId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                location.reload();
            } else {
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}